open(BUFF,"canonical_cds_lnc");
open(WRBUFF,">out_canonical_cds_lnc");
$prevchr = "";
$prevstop =0;
while($line=<BUFF>)
{
	chomp $line;
	@array = split(/\t/, $line);
	$chr = $array[0];
	$posstart = $array[1];
	$posstop = $array[2];
	$tran_name = $array[4];
	$startdiff =  $posstart+10000;
	$pstartdiff = $startdiff-10000;
	if(!exists($hash{$tran_name}))
	{
		$hash{$tran_name} = 0;
	}
	if($prevchr != $chr)
	{
		$prevstart =0;
	}
	$k =0;
	for($i=$posstart;$i>0;$i=$i-10000)
	{
		$k++;
		if($k == 12)
		{
			last;
		}
		if($i>$prevstop)
		{
			$startdiff =  $startdiff-10000;
			
			if($hash{$tran_name} == 0)
			{
				print WRBUFF $line."\n";
				$hash{$tran_name}++;
			}
			elsif($startdiff > 0)
			{
				$array[2] =$pstartdiff-1;
				$array[1] = $startdiff;
				$array[4] = $tran_name.'_'.$hash{$tran_name};
				$array[6] = $startdiff;
                                $array[7] = $pstartdiff-1;
				$line = join("\t",@array);
				print WRBUFF $line."\n";
				$hash{$tran_name}++;	 
			}
			else
			{

			}
			$pstartdiff = $startdiff;
		}
		else
		{
			last;
		}
	}	
	$prevstart = $posstart;
	$prevstop = $posstop;
	$prevchr = $chr;
}
        

